<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/8/26
 * Time: 15:16
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class  Complaint extends Base {
    public function index(){
        if (request()->isAjax()) {
            extract(input());
            $map =array();
            if(isset($keyword)&&$keyword!="")
            {
                $map['uuu.user_real_name|uuu.user_username'] = ['like',"%" . $keyword . "%"];
            }
            if(isset($keyword1)&&$keyword1!="")
            {
                $map['uuu.user_phone'] = ['like',"%" . $keyword1 . "%"];
            }
            if(isset($keyword2)&&$keyword2!="")
            {
                $map['a.order_num'] = ['like',"%" . $keyword2 . "%"];
            }

            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 50;
            $count = Db::name('order_complaint')->alias('oc')
                ->join('up_order a','a.order_id = oc.order_id','left')
                ->join('up_u_user uuu','uuu.user_id = oc.user_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->where($map)
                ->count();// 获取总条数
            $lists = Db::name('order_complaint')->alias('oc')
                ->join('up_order a','a.order_id = oc.order_id','left')
                ->join('up_u_user uuu','uuu.user_id = oc.user_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->page($NowPage, $limits)
                ->where($map)
                ->field('oc.*,a.*,uuu.user_username,uuu.user_phone,uuu.user_real_name,
                 ua.district as go_sheng,ua1.district as go_shi,
                        ua2.district as to_sheng,ua3.district as to_shi')
                ->order('a.order_fb_time desc')
                ->select();
            foreach ($lists as $key=>&$vo){
                $vo['go_address'] = $vo['go_sheng'].'-'.$vo['go_shi'];
                $vo['to_address'] = $vo['to_sheng'].'-'.$vo['to_shi'];
            }

            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
}